Ext.define('Zm.controller.Login', {
    extend: 'Ext.app.Controller',
    views:[
        'system.Login'
    ],
    requires:['Zm.Common','Zm.i18n.Lang','Ext.form.*'],
    
    init: function(){
        var me = this;
        me.control({
            'login button[action=login]': {
                click: me.loginSys
            },
            'login textfield':{
                keydown:me.onKeyPress
            }
        });
    },
    
    onKeyPress: function(f,e,o){
        var v = e.getKey();
        if(v==Ext.EventObject.ENTER){
            this.loginSys(f);
        }
    },
    
    loginSys: function(button){
        var me = this,
            win = button.up('window'),
            form = win.down('form').getForm(),
            lang = Zm.i18n.Lang,
            cm = Zm.Common;
        if(form.isValid()){
            form.submit({
                url: g_app + '/Index/login',
                waitMsg: lang.loadText, 
                success: function(form,action){
                    win.close();
                    g_user = action.result.data;
                    me.application.initMain();
                },
                failure: cm.onFail
            });
        }
    }
});